#include <gtest/gtest.h>
#include <thread>
#include "scheduler/scheduler_factory.h"
#include "../sample/navigation_task.h"
#include "../sample/battery_level_check.h"
#include "../sample/screen_return_zero_task.h"
#include "scheduler/while_do_scheduler.h"
#include "scheduler/sequence_scheduler.h"
#include "task/task_controller.h"
#include "task/task_chain.h"

TEST(test_while_do_scheduler_demo, test_while_do_scheduler)
{
    auto battery_check = task::TaskFactory<BatteryLevelCheck>::createTask("battery_level_check");
    auto navigation_task = task::TaskFactory<NavigationTask>::createTask("navigation_task");

    auto while_do_scheduler = scheduler::SchedulerFactory<scheduler::WhileDoScheduler>::createScheduler("navigation_scheduler");
    while_do_scheduler->setWhileConditionTask(battery_check);
    while_do_scheduler->setExecuteTask(navigation_task);

    while_do_scheduler->run();

    EASE_INFO("done");
}

TEST(test_while_do_end_pass_scheduler_demo, test_while_do_scheduler)
{
    auto battery_check = task::TaskFactory<BatteryLevelCheck>::createTask("battery_level_check");
    auto navigation_task = task::TaskFactory<NavigationTask>::createTask("navigation_task");

    auto while_do_scheduler = scheduler::SchedulerFactory<scheduler::WhileDoScheduler>::createScheduler("navigation_scheduler");
    while_do_scheduler->setWhileConditionTask(battery_check);
    while_do_scheduler->setExecuteTask(navigation_task);
    while_do_scheduler->setEndCondition(task::TaskStatus::Success);

    while_do_scheduler->run();

    EASE_INFO("done");
}

TEST(test_while_do_end_fail_scheduler_demo, test_while_do_scheduler)
{
    auto battery_check = task::TaskFactory<BatteryLevelCheck>::createTask("battery_level_check");
    auto navigation_task = task::TaskFactory<NavigationTask>::createTask("navigation_task");

    auto while_do_scheduler = scheduler::SchedulerFactory<scheduler::WhileDoScheduler>::createScheduler("navigation_scheduler");
    while_do_scheduler->setWhileConditionTask(battery_check);
    while_do_scheduler->setExecuteTask(navigation_task);
    while_do_scheduler->setEndCondition(task::TaskStatus::Failure);

    while_do_scheduler->run();

    EASE_INFO("done");
}

TEST(test_while_do_end_fail_scheduler_demo2, test_while_do_scheduler)
{
    task::TaskController task_controller;
    task_controller.setMaxParallelTaskCount(2);

    auto battery_check = task::TaskFactory<BatteryLevelCheck>::createTask("battery_level_check");
    auto navigation_task = task::TaskFactory<NavigationTask>::createTask("navigation_task");

    auto while_do_scheduler = scheduler::SchedulerFactory<scheduler::WhileDoScheduler>::createScheduler("navigation_scheduler");

    while_do_scheduler->setExecuteTask(navigation_task);
    while_do_scheduler->setWhileConditionTask(battery_check);
    while_do_scheduler->setEndCondition(task::TaskStatus::Failure);

    auto scheduler2 = scheduler::SchedulerFactory<scheduler::SequenceScheduler>::createScheduler("test2");
    scheduler2->appendScheduler(while_do_scheduler);
    EASE_INFO("ready interpret");
    scheduler2->run();
    EASE_INFO("done");
}
